const Controller = require('egg').Controller;

let fruitList = [
    "香蕉",
    "香蕉",
    "香蕉",
    "香蕉",
    "香蕉",
    "香蕉"
]

class FruitsController extends Controller {
    async index() {
        this.ctx.body = fruitList;
    }
    async new() {
        this.ctx.body = `
                <form method="post" action="/fruits">
                    <input name="fruitName" />
                    <button>提交</button>
                </form>
            `
    }
    async create() {
        let fruit = this.ctx.request.body;
        fruitList.push(fruit.fruit)
        this.ctx.redirect("/fruits")
    }
    async update(){
        let id = this.ctx.params.id;
        let fruits = this.ctx.body.fruits;
        fruitList.splice(id,1,fruits)
    }
    async destroy(){
        let id = this.ctx.params.id;
        console.log(id)
        fruitList.splice(id,1)
        this.ctx.body = true
    }
    // async getID(){
        //     let id = this.ctx.params.id;
        //     this.ctx.body = `id值为${id}`
        // }
        // async createpage(){
            //     this.ctx.body = `
            //         <form method="post" action="/create">
            //             <input name="fruitName" />
            //             <button>提交</button>
            //         </form>
            //     `
            // }
    // async createfruit(){
    //     let fruit = this.ctx.request.body.fruitName;
    //     fruitList.push(fruit)
    //     this.ctx.body = `添加成功${fruitList}`
    // }
}
module.exports = FruitsController